const { defineConfig } = require('@vue/cli-service');
const { name } = require('./package.json');
const ScriptSetup = require('unplugin-vue2-script-setup/webpack').default;
// const path = require('path');
// function resolve(dir) {
//   return path.join(__dirname, dir);
// }
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    hot: true,
    // proxy: {
    //   '/api': {
    //     target: 'http://', //跨域请求的公共地址
    //     changeOrigin: true, //是否开启跨域
    //     pathRewrite: {
    //       '^/api': '/'
    //     }
    //   }
    // },
    port: 7076
  },
  chainWebpack: (config) => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .tap((options) => {
        options.compiler = require('vue-template-babel-compiler');
        return options;
      });
    config.plugin('html').tap((args) => {
      args[0].title = 'MAP新产品信息平台';
      return args;
    });
  },
  configureWebpack(config) {
    config.plugins.push(ScriptSetup({}));
    // 根据环境变量动态做配置
    if (process.env.NODE_ENV === 'dev') {
      config.name = 'MAP新产品信息平台';
    } else {
      config.name = 'MAP新产品信息平台';
      config.optimization.minimizer[0].options.minimizer.options.compress = Object.assign(
        config.optimization.minimizer[0].options.minimizer.options.compress,
        {
          drop_console: true
        }
      );
    }
    config.output.library = `${name}-[name]`;
    config.output.libraryTarget = 'umd';
    config.output.chunkLoadingGlobal = `webpackJsonp_${name}`;
    // config.resolve.alias['@projectPage'] = resolve('./src/views/projectPage');
    // config.resolve.alias['@engineeringPage'] = resolve('./src/views/engineeringPage');
  }
});
